package view;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;

import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.UndoManager;

import controller.EditController;
import controller.FileController;
import controller.FormatController;
import controller.HelpController;


/*
 * JanelaPrincipal.java
 *
 * Created on 09/02/2013, 15:51:03
 *
/**
 *
 * @author Larissa
 */
public class JanelaPrincipal extends javax.swing.JFrame {

    /** Creates new form JanelaPrincipal */
     FormatController formatController;
     FileController fileController;
     HelpController helpController;
     EditController editController;
     private UndoManager undo = new UndoManager();
     
     MainPanel painelPrincipalExtendido;
     boolean bold = false; boolean italic = false; boolean regular = false;
    public JanelaPrincipal() {
        super("RPad++");
        initComponents();
        this.setLocation(20, 20);
        this.setSize(new Dimension(820,600));
        inicializaInterface();
        
        fileController = new FileController();
        formatController = new FormatController();
        helpController = new HelpController();
        editController = new EditController();
        
        
           ((MainPanel)this.painelAuxiliar.getSelectedComponent()).getPainelTexto().getDocument().addUndoableEditListener( new UndoableEditListener() {
			public void undoableEditHappened( UndoableEditEvent e ) {
				//Remember the edit and update the menus
				undo.addEdit( e.getEdit() );
				//undoAction.update();
				//redoAction.update();
			}
		} );
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        painelPrincipal = new javax.swing.JPanel();
        fileTabbedPanel = new javax.swing.JTabbedPane();
        panelFile = new javax.swing.JPanel();
        toolBarFile = new javax.swing.JToolBar();
        buttonNew = new javax.swing.JButton();
        buttonOpen = new javax.swing.JButton();
        buttonPrint = new javax.swing.JButton();
        buttonSaveNormal = new javax.swing.JButton();
        buttonSaveAs = new javax.swing.JButton();
        buttonExit = new javax.swing.JButton();
        panelEdit = new javax.swing.JPanel();
        toolBarEdit1 = new javax.swing.JToolBar();
        buttonCopy = new javax.swing.JButton();
        buttonPaste = new javax.swing.JButton();
        buttonCut = new javax.swing.JButton();
        toolBarEdit2 = new javax.swing.JToolBar();
        buttonUndo = new javax.swing.JButton();
        buttonRedo = new javax.swing.JButton();
        toolBarEdit3 = new javax.swing.JToolBar();
        buttonFind = new javax.swing.JButton();
        buttonFindNext = new javax.swing.JButton();
        toolBarEdit4 = new javax.swing.JToolBar();
        buttonSelectAll = new javax.swing.JButton();
        panelFormat = new javax.swing.JPanel();
        fontTypeComboBox = new javax.swing.JComboBox();
        fontSizeComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        buttonBold = new javax.swing.JButton();
        buttonItalic = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        LabelPreviewFont = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        panelView = new javax.swing.JPanel();
        toolBarView = new javax.swing.JToolBar();
        buttonRulerBar = new javax.swing.JButton();
        buttonProperties = new javax.swing.JButton();
        panelHelp = new javax.swing.JPanel();
        toolBarHelp = new javax.swing.JToolBar();
        buttonAbout = new javax.swing.JButton();
        painelAuxiliar = new javax.swing.JTabbedPane();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        fileTabbedPanel.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N

        panelFile.setMaximumSize(new java.awt.Dimension(810, 32767));
        panelFile.setMinimumSize(new java.awt.Dimension(100, 10));
        panelFile.setPreferredSize(new java.awt.Dimension(810, 102));

        toolBarFile.setRollover(true);
        toolBarFile.setMinimumSize(new java.awt.Dimension(60, 10));

        buttonNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/new.png"))); // NOI18N
        buttonNew.setText("New");
        buttonNew.setFocusable(false);
        buttonNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNewActionPerformed(evt);
            }
        });
        toolBarFile.add(buttonNew);

        buttonOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/open.png"))); // NOI18N
        buttonOpen.setText("Open");
        buttonOpen.setFocusable(false);
        buttonOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOpenActionPerformed(evt);
            }
        });
        toolBarFile.add(buttonOpen);

        buttonPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/print.png"))); // NOI18N
        buttonPrint.setText("Print");
        buttonPrint.setFocusable(false);
        buttonPrint.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonPrint.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPrintActionPerformed(evt);
            }
        });
        toolBarFile.add(buttonPrint);

        buttonSaveNormal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/save.png"))); // NOI18N
        buttonSaveNormal.setText("Save");
        buttonSaveNormal.setFocusable(false);
        buttonSaveNormal.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonSaveNormal.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonSaveNormal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSaveNormalActionPerformed(evt);
            }
        });
        toolBarFile.add(buttonSaveNormal);

        buttonSaveAs.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/saveAs.png"))); // NOI18N
        buttonSaveAs.setText("Save As");
        buttonSaveAs.setFocusable(false);
        buttonSaveAs.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonSaveAs.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonSaveAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSaveAsActionPerformed(evt);
            }
        });
        toolBarFile.add(buttonSaveAs);

        buttonExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/close.png"))); // NOI18N
        buttonExit.setText("Exit");
        buttonExit.setFocusable(false);
        buttonExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExitActionPerformed(evt);
            }
        });
        toolBarFile.add(buttonExit);

        javax.swing.GroupLayout panelFileLayout = new javax.swing.GroupLayout(panelFile);
        panelFile.setLayout(panelFileLayout);
        panelFileLayout.setHorizontalGroup(
            panelFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFileLayout.createSequentialGroup()
                .addComponent(toolBarFile, javax.swing.GroupLayout.PREFERRED_SIZE, 798, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 88, Short.MAX_VALUE))
        );
        panelFileLayout.setVerticalGroup(
            panelFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFileLayout.createSequentialGroup()
                .addComponent(toolBarFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        fileTabbedPanel.addTab("File", panelFile);

        toolBarEdit1.setRollover(true);

        buttonCopy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/copy.png"))); // NOI18N
        buttonCopy.setText("Copy");
        buttonCopy.setFocusable(false);
        buttonCopy.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonCopy.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonCopy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCopyActionPerformed(evt);
            }
        });
        toolBarEdit1.add(buttonCopy);

        buttonPaste.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/paste.png"))); // NOI18N
        buttonPaste.setText("Paste");
        buttonPaste.setFocusable(false);
        buttonPaste.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonPaste.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonPaste.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPasteActionPerformed(evt);
            }
        });
        toolBarEdit1.add(buttonPaste);

        buttonCut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cut.png"))); // NOI18N
        buttonCut.setText("Cut");
        buttonCut.setFocusable(false);
        buttonCut.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonCut.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonCut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCutActionPerformed(evt);
            }
        });
        toolBarEdit1.add(buttonCut);

        toolBarEdit2.setRollover(true);

        buttonUndo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/undo.png"))); // NOI18N
        buttonUndo.setText("Undo");
        buttonUndo.setFocusable(false);
        buttonUndo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonUndo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonUndo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonUndoActionPerformed(evt);
            }
        });
        toolBarEdit2.add(buttonUndo);

        buttonRedo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/redo.png"))); // NOI18N
        buttonRedo.setText("Redo");
        buttonRedo.setFocusable(false);
        buttonRedo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonRedo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonRedo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRedoActionPerformed(evt);
            }
        });
        toolBarEdit2.add(buttonRedo);

        toolBarEdit3.setRollover(true);

        buttonFind.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/find.png"))); // NOI18N
        buttonFind.setText("Find");
        buttonFind.setFocusable(false);
        buttonFind.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonFind.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFindActionPerformed(evt);
            }
        });
        toolBarEdit3.add(buttonFind);

        buttonFindNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/findNext.png"))); // NOI18N
        buttonFindNext.setText("Find Next");
        buttonFindNext.setFocusable(false);
        buttonFindNext.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonFindNext.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonFindNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFindNextActionPerformed(evt);
            }
        });
        toolBarEdit3.add(buttonFindNext);

        toolBarEdit4.setRollover(true);

        buttonSelectAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/select.png"))); // NOI18N
        buttonSelectAll.setText("Select All");
        buttonSelectAll.setFocusable(false);
        buttonSelectAll.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonSelectAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSelectAllActionPerformed(evt);
            }
        });
        toolBarEdit4.add(buttonSelectAll);

        javax.swing.GroupLayout panelEditLayout = new javax.swing.GroupLayout(panelEdit);
        panelEdit.setLayout(panelEditLayout);
        panelEditLayout.setHorizontalGroup(
            panelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelEditLayout.createSequentialGroup()
                .addComponent(toolBarEdit1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(toolBarEdit2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(toolBarEdit3, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(toolBarEdit4, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE))
        );
        panelEditLayout.setVerticalGroup(
            panelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBarEdit1, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
            .addComponent(toolBarEdit2, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
            .addComponent(toolBarEdit3, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
            .addComponent(toolBarEdit4, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
        );

        fileTabbedPanel.addTab("Edit", panelEdit);

        fontTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Calibri", "Times New Roman", " " }));
        fontTypeComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                fontTypeComboBoxItemStateChanged(evt);
            }
        });

        fontSizeComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                fontSizeComboBoxItemStateChanged(evt);
            }
        });

        jLabel1.setText("Font-type:");

        jLabel2.setText("Size");

        jLabel3.setText("Font-style:");

        jToolBar1.setRollover(true);

        buttonBold.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/bold.png"))); // NOI18N
        buttonBold.setFocusable(false);
        buttonBold.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonBold.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonBold.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBoldActionPerformed(evt);
            }
        });
        jToolBar1.add(buttonBold);

        buttonItalic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/italic.png"))); // NOI18N
        buttonItalic.setFocusable(false);
        buttonItalic.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonItalic.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonItalic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonItalicActionPerformed(evt);
            }
        });
        jToolBar1.add(buttonItalic);

        jLabel4.setText("Font-Preview:");

        LabelPreviewFont.setText("AaBaCcDdeEfFgGhHjJ");
        LabelPreviewFont.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        jCheckBox1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jCheckBox1.setText("Highlight Java Key-Words");
        jCheckBox1.setToolTipText("");
        jCheckBox1.setName("cboHighlight"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelFormatLayout = new javax.swing.GroupLayout(panelFormat);
        panelFormat.setLayout(panelFormatLayout);
        panelFormatLayout.setHorizontalGroup(
            panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFormatLayout.createSequentialGroup()
                .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jLabel1))
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addComponent(fontTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGap(113, 113, 113)
                        .addComponent(jLabel2)
                        .addGap(106, 106, 106)
                        .addComponent(jLabel3))
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGap(91, 91, 91)
                        .addComponent(fontSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(55, 55, 55)
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(LabelPreviewFont, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(117, Short.MAX_VALUE))
        );
        panelFormatLayout.setVerticalGroup(
            panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFormatLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(panelFormatLayout.createSequentialGroup()
                        .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LabelPreviewFont, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(panelFormatLayout.createSequentialGroup()
                                .addGroup(panelFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(fontTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(fontSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jCheckBox1)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        fileTabbedPanel.addTab("Format", panelFormat);

        toolBarView.setRollover(true);

        buttonRulerBar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/ruler.png"))); // NOI18N
        buttonRulerBar.setText("RulerBar");
        buttonRulerBar.setFocusable(false);
        buttonRulerBar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonRulerBar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonRulerBar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRulerBarActionPerformed(evt);
            }
        });
        toolBarView.add(buttonRulerBar);

        buttonProperties.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/properties.png"))); // NOI18N
        buttonProperties.setText("Properties");
        buttonProperties.setFocusable(false);
        buttonProperties.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonProperties.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonProperties.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPropertiesActionPerformed(evt);
            }
        });
        toolBarView.add(buttonProperties);

        javax.swing.GroupLayout panelViewLayout = new javax.swing.GroupLayout(panelView);
        panelView.setLayout(panelViewLayout);
        panelViewLayout.setHorizontalGroup(
            panelViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBarView, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE)
        );
        panelViewLayout.setVerticalGroup(
            panelViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBarView, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
        );

        fileTabbedPanel.addTab("View", panelView);

        toolBarHelp.setRollover(true);

        buttonAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/about.png"))); // NOI18N
        buttonAbout.setText("About");
        buttonAbout.setFocusable(false);
        buttonAbout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonAbout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAboutActionPerformed(evt);
            }
        });
        toolBarHelp.add(buttonAbout);

        javax.swing.GroupLayout panelHelpLayout = new javax.swing.GroupLayout(panelHelp);
        panelHelp.setLayout(panelHelpLayout);
        panelHelpLayout.setHorizontalGroup(
            panelHelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBarHelp, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE)
        );
        panelHelpLayout.setVerticalGroup(
            panelHelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBarHelp, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
        );

        fileTabbedPanel.addTab("Help", panelHelp);

        painelAuxiliar.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        painelAuxiliar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        painelAuxiliar.setMaximumSize(new java.awt.Dimension(795, 32767));
        painelAuxiliar.setName("cboHighlight"); // NOI18N

        javax.swing.GroupLayout painelPrincipalLayout = new javax.swing.GroupLayout(painelPrincipal);
        painelPrincipal.setLayout(painelPrincipalLayout);
        painelPrincipalLayout.setHorizontalGroup(
            painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(fileTabbedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(painelPrincipalLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(painelAuxiliar, javax.swing.GroupLayout.PREFERRED_SIZE, 795, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(86, 86, 86))
        );
        painelPrincipalLayout.setVerticalGroup(
            painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelPrincipalLayout.createSequentialGroup()
                .addComponent(fileTabbedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(painelAuxiliar, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //**Muda: Tem que comentar uma das duas linhas abaixo para executar
    private void buttonOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOpenActionPerformed
    	fileController.openFileMulti(this, (MainPanel)this.painelAuxiliar.getSelectedComponent(), painelAuxiliar); //Multi
    }//GEN-LAST:event_buttonOpenActionPerformed

    private void buttonPrintActionPerformed(java.awt.event.ActionEvent evt) {                                             
        fileController.printPage(); //corrigir
    }
    
    private void buttonSaveNormalActionPerformed(java.awt.event.ActionEvent evt) {                                             
        fileController.saveNormal((MainPanel)this.painelAuxiliar.getSelectedComponent(), painelAuxiliar); //corrigir
    }                                            
    
    private void buttonSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveAsActionPerformed
        fileController.saveAs((MainPanel)this.painelAuxiliar.getSelectedComponent(), painelAuxiliar); //corrigir
    }//GEN-LAST:event_buttonSaveAsActionPerformed

    private void buttonRulerBarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRulerBarActionPerformed
        formatController.ocultaReguaController((MainPanel)this.painelAuxiliar.getSelectedComponent());
    }//GEN-LAST:event_buttonRulerBarActionPerformed

    //**Muda: Tem que comentar uma das duas linhas abaixo para executar
    private void buttonNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNewActionPerformed
       fileController.newFileMulti(this.painelAuxiliar, undo); //multi
    }//GEN-LAST:event_buttonNewActionPerformed
    
    private void buttonUndoActionPerformed(java.awt.event.ActionEvent evt) {                                            
    	editController.undo(undo);
    }
    
    private void buttonRedoActionPerformed(java.awt.event.ActionEvent evt) {                                            
    	editController.redo(undo);
    }
    
    private void buttonFindActionPerformed(java.awt.event.ActionEvent evt) {                                            
    	editController.findBinaryController( (MainPanel)this.painelAuxiliar.getSelectedComponent());
    }
    
    private void buttonFindNextActionPerformed(java.awt.event.ActionEvent evt) {                                            
    	editController.findNextController((MainPanel)this.painelAuxiliar.getSelectedComponent());
    }
    
    private void buttonAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAboutActionPerformed
        helpController.aboutSystem();
    }//GEN-LAST:event_buttonAboutActionPerformed

	private void buttonPropertiesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPropertiesActionPerformed
        fileController.fileProperties(this, (MainPanel)this.painelAuxiliar.getSelectedComponent());
        
    }//GEN-LAST:event_buttonPropertiesActionPerformed

    //**Muda: Tem que comentar uma das duas linhas abaixo para executar
    private void buttonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExitActionPerformed
        fileController.exitMulti((MainPanel)this.painelAuxiliar.getSelectedComponent(), painelAuxiliar); //corrigir
    }//GEN-LAST:event_buttonExitActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        MainPanel m = (MainPanel)this.painelAuxiliar.getSelectedComponent();
        if(jCheckBox1.isSelected()){
            formatController.highlight(m.getPainelTexto());
        } else {
            formatController.removeHighlight(m.getPainelTexto());
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void buttonItalicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonItalicActionPerformed
        if (italic)
        italic = false;
        else
        italic = true;
        formatController.ajustaFonte(String.valueOf(this.fontTypeComboBox.getSelectedItem()),testaFonte(), String.valueOf(fontSizeComboBox.getSelectedItem()), LabelPreviewFont, (MainPanel)this.painelAuxiliar.getSelectedComponent());
    }//GEN-LAST:event_buttonItalicActionPerformed

    private void buttonBoldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBoldActionPerformed
        if (bold)
        bold = false;
        else
        bold = true;
        formatController.ajustaFonte(String.valueOf(this.fontTypeComboBox.getSelectedItem()),testaFonte(), String.valueOf(fontSizeComboBox.getSelectedItem()), LabelPreviewFont, (MainPanel)this.painelAuxiliar.getSelectedComponent());
    }//GEN-LAST:event_buttonBoldActionPerformed

    private void fontSizeComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontSizeComboBoxItemStateChanged
        formatController.ajustaFonte(String.valueOf(this.fontTypeComboBox.getSelectedItem()),testaFonte(), String.valueOf(fontSizeComboBox.getSelectedItem()), LabelPreviewFont,(MainPanel)this.painelAuxiliar.getSelectedComponent());
    }//GEN-LAST:event_fontSizeComboBoxItemStateChanged

    private void fontTypeComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontTypeComboBoxItemStateChanged
        formatController.ajustaFonte(String.valueOf(this.fontTypeComboBox.getSelectedItem()),testaFonte(), String.valueOf(fontSizeComboBox.getSelectedItem()), LabelPreviewFont,(MainPanel)this.painelAuxiliar.getSelectedComponent());
    }//GEN-LAST:event_fontTypeComboBoxItemStateChanged

    private void buttonCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCopyActionPerformed
        editController.copy(painelPrincipalExtendido);
    }//GEN-LAST:event_buttonCopyActionPerformed

    private void buttonPasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPasteActionPerformed
        editController.paste(painelPrincipalExtendido);
    }//GEN-LAST:event_buttonPasteActionPerformed

    private void buttonCutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCutActionPerformed
        editController.cut(painelPrincipalExtendido);
    }//GEN-LAST:event_buttonCutActionPerformed

    private void buttonSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectAllActionPerformed
        editController.selectedAll(painelPrincipalExtendido);
    }//GEN-LAST:event_buttonSelectAllActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                } catch (Exception e) {
                    e.printStackTrace();
                }

                new JanelaPrincipal().setVisible(true);
                }
        });
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel LabelPreviewFont;
    private javax.swing.JButton buttonAbout;
    private javax.swing.JButton buttonBold;
    private javax.swing.JButton buttonCopy;
    private javax.swing.JButton buttonCut;
    private javax.swing.JButton buttonExit;
    private javax.swing.JButton buttonFind;
    private javax.swing.JButton buttonFindNext;
    private javax.swing.JButton buttonItalic;
    private javax.swing.JButton buttonNew;
    private javax.swing.JButton buttonOpen;
    private javax.swing.JButton buttonPaste;
    private javax.swing.JButton buttonPrint;
    private javax.swing.JButton buttonProperties;
    private javax.swing.JButton buttonRedo;
    private javax.swing.JButton buttonRulerBar;
    private javax.swing.JButton buttonSaveAs;
    private javax.swing.JButton buttonSaveNormal;
    private javax.swing.JButton buttonSelectAll;
    private javax.swing.JButton buttonUndo;
    private javax.swing.JTabbedPane fileTabbedPanel;
    private javax.swing.JComboBox fontSizeComboBox;
    private javax.swing.JComboBox fontTypeComboBox;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTabbedPane painelAuxiliar;
    private javax.swing.JPanel painelPrincipal;
    private javax.swing.JPanel panelEdit;
    private javax.swing.JPanel panelFile;
    private javax.swing.JPanel panelFormat;
    private javax.swing.JPanel panelHelp;
    private javax.swing.JPanel panelView;
    private javax.swing.JToolBar toolBarEdit1;
    private javax.swing.JToolBar toolBarEdit2;
    private javax.swing.JToolBar toolBarEdit3;
    private javax.swing.JToolBar toolBarEdit4;
    private javax.swing.JToolBar toolBarFile;
    private javax.swing.JToolBar toolBarHelp;
    private javax.swing.JToolBar toolBarView;
    // End of variables declaration//GEN-END:variables
    
    private void inicializaInterface() {
        
        painelPrincipalExtendido = new MainPanel();
        this.painelAuxiliar.add(painelPrincipalExtendido);
        this.painelAuxiliar.setTitleAt(0, "Untitled");
        this.painelAuxiliar.setIconAt(0, new ImageIcon((getClass().getResource("/imagens/fileUntitled.png"))));
        
        
        String fonts[]=GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        String sizes[] = {"8","10","12","14","16","18","20","24","28","32","48","60"};
        
        this.fontTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(fonts));
        this.fontSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(sizes));
    }
    

    
    
   public int testaFonte() {
       if (bold && !italic)
           return 1;
       else if (bold && italic )
           return 3;
       else if (!bold && italic)
           return 2;
       else
           return 0;
   }
   
}
